<?php
$loginName=$_REQUEST["loginName"];
echo $loginName;
echo "<br>";
$password=$_REQUEST["password"];
echo $password;
echo "<br>";
$rePassword=$_REQUEST["rePassword"];
echo $rePassword;
echo "<br>";
$hobbies=$_REQUEST["hobby"];
print_r($hobbies) ;
echo "<br>";


require_once("DButil.php");
$conn=getConn();
// mysqli_query($conn,"begin");
// $success=true;
//判断登录名是否重复
$sql="select u_login_name from t_user where u_login_name ='{$loginName}'";
$result=mysqli_query($conn,$sql);
if($result){
   if(mysqli_num_rows($result)){
    header("location:http://localhost/day04/registerPage.php?msg=登录名重复");
    return;
   }
}


$sql2="insert into t_user (u_login_name,u_password,u_phone) values('{$loginName}','{$password}','{$hobbies}')";
$result2=mysqli_query($conn,$sql2);
// echo "<div>";
// var_dump($result);
// echo "</div>";
if($result2){
    // $success=false;
      echo "注册成功";
}else{
    $msg=mysqli_error($conn);
    header("location:http://localhost/day04/registerPage.php?msg={$msg}");
    // echo "<div>".mysqli_error($conn)."</div>";
}
// if($success){
//     // 全部都成功后, 提交事务
//     mysqli_query($conn, "commit");
// } else {
//     // 未全部都成功, 撤销执行的操作( 回滚事务 )
//     mysqli_query($conn, "rollback");
// }







?>